package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Seckill_Sku_Relation_Mapper;
import com.shop.pojo.sms.Sms_Seckill_Sku_Relation;
import com.shop.service.Sms_Seckill_Sku_Relation_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 秒杀活动商品关联
 */
@Service
public class Sms_Seckill_Sku_Relation_ServiceImpl implements Sms_Seckill_Sku_Relation_Service {

    @Autowired
    private Sms_Seckill_Sku_Relation_Mapper sms_seckill_sku_relation_mapper;


    /***
     * 后台秒杀关联商品的显示所有
     * @param pages
     * @param sssr
     * @return
     */
    @Override
    public LayuiUtils<Sms_Seckill_Sku_Relation> find_admin_seckill_sku_relation_All(Page<Sms_Seckill_Sku_Relation> pages, Sms_Seckill_Sku_Relation sssr) {
        LayuiUtils<Sms_Seckill_Sku_Relation> layuis = new LayuiUtils<>();


        QueryWrapper<Sms_Seckill_Sku_Relation> query = new QueryWrapper<>();

        query.eq("promotion_session_id",sssr.getPromotion_session_id());

        Page<Sms_Seckill_Sku_Relation> sms_seckill_sku_relationPage = sms_seckill_sku_relation_mapper.selectPage(pages, query);

        layuis.setCount(sms_seckill_sku_relationPage.getTotal());
        layuis.setData(sms_seckill_sku_relationPage.getRecords());

        return layuis;
    }

    /**
     * 后台秒杀关联商品的新增
     * @param sssr
     * @return
     */
    @Override
    public R insert_admin_seckill_sku_relation_All(Sms_Seckill_Sku_Relation sssr) {

        int insert = sms_seckill_sku_relation_mapper.insert(sssr);

        if(insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 后台秒杀关联商品的删除
     * @param id
     * @return
     */
    @Override
    public R del_admin_seckill_sku_relation_All(List<Integer> id) {

        int i = sms_seckill_sku_relation_mapper.deleteBatchIds(id);

        if(i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /**
     * 后台秒杀关联商品的修改
     * @param sssr
     * @return
     */
    @Override
    public R up_admin_seckill_sku_relation_All(Sms_Seckill_Sku_Relation sssr) {
        int i = sms_seckill_sku_relation_mapper.updateById(sssr);
        if(i > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
